package com.qubyer.widget.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

abstract class BindingRvAdapter<T, DB : ViewDataBinding>(dataList: ArrayList<T> = ArrayList()) : RvAdapter<T, BindingViewHolder<DB>>(dataList) {

    abstract val itemLayout: Int

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BindingViewHolder<DB> {
        return BindingViewHolder(DataBindingUtil.inflate(LayoutInflater.from(mContext), itemLayout, parent, false))
    }

    override fun onBindViewHolder(holder: BindingViewHolder<DB>, position: Int) {
        onBind(getItem(position), holder.dataBinding)
        holder.dataBinding.executePendingBindings()
    }

    abstract fun onBind(data: T, dataBinding: DB)

}